﻿$(function () {
    layui.use(['element', 'notice', 'layer', 'table','iziToast'], function () {
        var layer = layui.layer,
            element = layui.element,
            table = layui.table,
            notice = Util.notice !== null && Util.notice() !== null
                ? Util.notice() : layui.notice,
            iziToast = layui.iziToast;
       
        //初始化
        let tableIns = table.render(advertisetableconfig);
        //监听表格数据行按钮
        let editurl = "/business/advertisemanage/edit",
            editWidowConfig = {
                title: "编辑/修改",
                type: 2,
                content: "",
                fixtolayoutbody: true,
                anim: 3,
                end: function () {
                    tableIns.reload();
                }
            },
            currentSystemModuleId = $("#currentSystemModuleId").val();
        table.on('tool(advertisemanagetable)', function (obj) {
            var data = obj.data,
                thisElem = this,
                buttonid = layui.$(thisElem).data("buttonid");
            if (obj.event === 'Edit') {
                editWidowConfig.content = editurl + "?moduleid=" + currentSystemModuleId + "&buttonid=" + buttonid + "&advid=" + data.Id;
                Util.OpenMainWindow(editWidowConfig);
            } else if (obj.event === 'Delete') {
                layer.confirm("确定要进行删除操作吗？", function (confirmIndex) {
                    layer.close(confirmIndex);
                    iziToast.loading("删除中，请稍候...");
                    let node = new Object(DeleteNodeModel);
                    node.EntityId = data.Id;
                    node.ButtonId = buttonid;
                    node.ModuleId = currentSystemModuleId;
                    $.deleteJSON("/api/backend/business/advertisemanage/delete", node, function (res) {
                        iziToast.destroy();
                        if (!httpapi.checkResponse(res)) {
                            //输入信息校验错误
                            notice.error(res.message);
                        } else {//Success
                            notice.success(res.message);
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        }
                    });
                });
            }
        });
        ////监听顶部按钮栏
        var PageButtonEvent = {
            Add: function (buttonid) {
                editWidowConfig.content = editurl + "?moduleid=" + currentSystemModuleId + "&buttonid=" + buttonid;
                Util.OpenMainWindow(editWidowConfig);
                return false;
            }
        };
        $('.pagebuttongroup .layui-btn').on('click', function (e) {
            e.preventDefault();
            var type = $(this).data('type');
            var buttonid = $(this).data("buttonid");
            PageButtonEvent[type] ? PageButtonEvent[type].call(this, buttonid) : '';
        });
    });//layui.use([
}); //$(function () {